//
//  BaseNaviBar.swift
//  DWater-Swift
//
//  Created by mac on 2017/4/18.
//  Copyright © 2017年 Dimon.胡亚宾. All rights reserved.
//

import UIKit
class BaseNaviBar: UIView {

    var titleLabel  : UILabel?
    var titleImage  : UIImageView?
    var leftView    : UIView?{
        didSet{
            leftView?.setLeft(10.0)
            leftView?.center.y = self.height/2+10;
            if leftView != nil {
                self.backButton = nil
            }
            leftView?.removeFromSuperview()
            self.addSubview(leftView!)
        }
    
    }
    var rightView   : UIView?{
        didSet{
            rightView?.setRight(SCREEN_WIDTH - 10)
            rightView?.setCenterY(self.height/2 + 10)
            rightView?.removeFromSuperview()
            self.addSubview(rightView!)
        }
    }
    var backButton  : UIButton?
    var bgImageView : UIImageView?
    var title       : NSString?{
        didSet{
        self.titleLabel?.text = title as String?;
        }
    }
    
    var image       : UIImage?{
        didSet{
        self.titleImage?.image = image ;
        }
    }
    
    override init(frame: CGRect) {
        let frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH , height: 64)
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.clear
        self.bgImageView = UIImageView(frame:self.bounds)
        self.bgImageView?.backgroundColor = UIColor.clear
        self.bgImageView?.isUserInteractionEnabled = true
        self.insertSubview(self.bgImageView!, at: 0)
       
        self.titleImage = UIImageView(frame:CGRect(x: 60, y: 0, width: SCREEN_WIDTH-120, height: SCREEN_HEIGHT))
        self.titleImage?.isUserInteractionEnabled = false
        self.addSubview(self.titleImage!)
        
        self.titleLabel = UILabel(frame:self.bounds)
        self.titleLabel?.backgroundColor = UIColor.clear
        self.titleLabel?.font = UIFont.systemFont(ofSize: 17)
        self.titleLabel?.textAlignment = .center
        self.titleLabel?.textColor = UIColor.white
        self.titleLabel?.isUserInteractionEnabled = false
        self.addSubview(self.titleLabel!)
       
    }
   
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
}
